home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
boss
/
boss_doc.lzh
/
WN_PDOWN.DOC
< prev
Wrap
Text File
|
1992-03-08
|
18KB
|
468 lines
PDMENU AND PDITEM DATA STRUCTURES:
The heart of the pulldown menu system is the menu structure pdmenu. Each
menu has its own pdmenu structure which describes the menu.
The structure is defined in WINBOSS.H.
struct pditem { /* PULLDOWN menu item template */
int r; /* row in menu window for item */
int c; /* col in menu window for item*/
char *t; /* menu item text */
char hkc; /* the menu HotKey*/
int status; /* item status - active/in-active */
char type; /* item type, action, toggle,etc. */
int rv; /* item return value */
};
struct pdmenu { /* PULLDOWN menu structure */
WINDOWPTR wpsave; /* menu's window pointer */
int wa; /* window attribute */
int ba; /* border attribute */
int hka; /* hot key attribute */
int winopn; /* window is open flag */
int lndx; /* last index selected */
int fm; /* first menu item index */
int lm; /* last menu item index */
struct pditem item[WN_MXROWS*4]; /* a bunch of menu items */
} WNPD, *WNPDPTR; /* NOTE RELATIVE LIMIT */
The structure pditem is modelled on the structure pitem but has several
new fields.
The MENU HOTKEY is any letter in the menu text. The key is highlighted in
a menu display and pressing this key will immediately select the menu
item. The hotkey must have the same case (upper/lower) as its
corresponding letter in the menu text.
The STATUS field defines whether a menu item is active (1) or inactive (0).
Active items have their hotkeys highlighted and can be
selected by the user. Inactive menu items do not have their hotkey
highlighted and cannot be selected by the user.
The TYPE field holds a interger which defines the item's type.
Currently, there are 5 types available.
PDACTION - the item is an Action item. That is, selecting it will
invoke some action. Load, Save, Print are examples of Action items.
PDSELECT - an Action item that has been Selected. A program can use the
routine wn_pdtype to switch an PDACTION item to a PDSELECT item to signal
other parts of the program that the item has been selected.
For example, before a program prints, it can check the Load option to
see if the user has loaded any data.
PDBAR - this type is only used in a bar menu. It means that the item does
not have an associated pulldown menu.
PDTOGG - the item is a toggle. That is, selecting it simply toggles the
item ON and OFF.
PDETOGG - the item is an EXCLUSIVE toggle. Only one exclusive type toggle
in a menu can be ON. Turning one ON turns another OFF.
The RV field is the items return value.
PULLDOWN MENU ROUTINES:
The wn_pd pulldown system uses 10 routines which are briefly described
here.
wn_pdopen - opens a menu window if it is not yet open. Displays all the
menu items. The menu can be displayed as inactive or active. An active
menu has its item hotkeys highlighted. The only menu that would normally
be displayed as inactive would be the main bar menu.
wn_pdclose - closes a menu window.
wn_pdupdate - displays a specified item in normal or reverse video.
Primarily used by wn_pdget to indicate the current menu item being
pointed to.
wn_pdgettog - this routine has two uses. If it is supplied with a menu
item's return value (rv), it returns TRUE if the toggle is ON or FALSE if the
toggle is OFF. If it is supplied with a value of -1 instead of a return
value, it returns PDTOGOK if all menu toggles are OFF or the return value of
a toggle that is ON. The -1 option is primarily used to determine which, if
any, of a set of EXCLUSIVE toggles (mutually exclusive toggles) is ON.
wn_pdsettog - primarily used by wn_pdget to reverse the state of a toggle
when the user selects a toggle menu item. If the toggle is an exclusive type
and it has been turned ON, the routine turns OFF all other toggles in the
menu and returns the menu item INDEX of a toggle that was previously ON.
If none were ON, it returns PDTOGOK.
wn_pdactive - this routine takes a menu option's return value and
activates or de-activates the menu option based on the value of a second
argument. A program can use this routine to control which options a user
has available at any particular point in the program. This is one of
the systems most powerful features.
wn_pdtype - this routine serves two purposes. It can change the type code
of a menu item or return its current type code. This routine should only
be used to change type Action or type Selected or the reverse.
It's primary use is to let the type code serve as a flag that can be
tested to see if an item has been selected or not. As an example, the
code that exits a program can check the Load and Save menu items, if Load
has been selected, but Save has not, then it should ask the user if he
wants to save his data before exiting the program. NOTE: the system does not
automatically switch an Active type to a Selected type when an item is
selected. It is the program's duty to do this.
wn_pdget - this is the real work horse. It gets the user's menu choice
and returns the item's return code. A menu must be opened using wn_pdopen
BEFORE calling this routine. wn_pdget first displays the current choice
in reverse video. If all items in a menu are inactive, none are
highlighted. It then waits for the user to make a selection using the
arrow keys and ENTER or by pressing an item's hotkey. If the selected
item is not a toggle, the item's return code is returned. If it is a
toggle, its state is reversed, but the routine does not exit. If the user
presses ESC, the routine closes the menu window and returns 99.
Wn_pdget handles pulldown menus in a special way. When in a pulldown,
pressing the left arrow key returns 97 and pressing the right arrow key
returns 98. In both cases, the window is closed. The application program
can use these codes to take special action. The program PDDEMO
demonstrates one way of handling these codes by immediately activating
the adjacent main bar menu item and displaying its pulldown. In this way,
once a user has pulled down one menu, he can look at all the other
pulldown menus simply by pressing the left and right arrow keys.
wn_border - this is a handy little routine to select a single or double
ruled border for all subsequent windows.
wn_drawborder - this routine immediately redraws the border of a
specified window as single or double ruled.
THE PDDEMO PROGRAM:
As well as giving a good demonstration of the power of the system, this
program contains the basic code to implement almost all common menu
activities and one or two less common ones. As such, it can serve as the
basis for implementing your own menu system, probably with only minor
changes and the addition of routines that implement the actions of the
various menu items.
The look and contents are based on the menus found in many Microsoft
applications such as QuickBasic, QuickC, Windows and Excel.
The one thing where PDDEMO differs markedly from MS is in the key that
activates the main bar menu. I've used the slash key (like Lotus 123)
rather than the ALT key.
PDDEMO contains examples of toggle items (Setup/Color), exclusive toggles
(Setup/Printers), activating and de-activating menu options and even a
neat example of how turning ON a toggle in one menu, de-activates the
same option in another menu. Try selecting the same item for both the X
and Y axis using the View/Graphics option. Two level and three level
nested menus are also demonstrated. Most of the pulldown menus are
'single shot' menus. That is, you make a selection and then you are
returned to the main program. A couple are 'sticky' menus that allow you
to make several selections from the sam